package concurrent.countDownLatch;

import java.util.concurrent.CountDownLatch;

/**
 * Author: Jason Wu
 * Date  : 2013-11-11
 */
public class MainCountDownLatch {
    public static void main(String[] args) {
        CountDownLatch begSignal = new CountDownLatch(1);
        int playerCount = 8;
        CountDownLatch endSignal = new CountDownLatch(playerCount);

        for (int i = 0; i < playerCount; i++) {
            new Thread(new Work(String.format("Player-%s", i), 10000, begSignal, endSignal)).start();
        }
        try {
            Thread.sleep(1000);
            begSignal.countDown();
            endSignal.await();
            System.out.println("game over !!");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
